/*
 * Copyright 2004 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.sf.jsfcomp.chartcreator.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import net.sf.jsfcomp.chartcreator.component.UIChart;
import net.sf.jsfcomp.chartcreator.component.UIChartAxis;

/**
 * Holds the chart information to be rendered. This class lives in session when
 * the chart rendering begins and removes when the request is completed.
 * 
 * @author Cagatay Civici (latest modification by $Author: mustafaulu.net $)
 * @since 1.2.0
 */
public class ChartData implements Serializable {

    private Object datasource;
    private int width;
    private int height;
    private int alpha;
    private int depth;
    private int startAngle;
    private double explode;
    private String title;
    private String type;
    private String background;
    private String foreground;
    private String xlabel;
    private String ylabel;
    private String orientation;
    private String colors;
    private boolean chart3d;
    private boolean legend;
    private String legendPosition;
    private float legendFontSize;
    private boolean legendBorder;
    private boolean antialias;
    private boolean outline;
    private boolean barOutline;
    private String output;
    private List extensions;
    private String generateMap;
    private boolean domainGridLines;
    private boolean rangeGridLines;
    private float lineStokeWidth;
    private String dataTooltipFormat;
    private String pieLabelBackground;
    private String pieLabelOutline;

    public ChartData() {
        //
    }

    public ChartData(UIChart chart) {
        this.datasource = chart.getDatasource();
        this.width = chart.getWidth();
        this.height = chart.getHeight();
        this.alpha = chart.getAlpha();
        this.depth = chart.getDepth();
        this.startAngle = chart.getStartAngle();
        this.explode = chart.getExplode();
        this.title = chart.getTitle();
        this.type = chart.getType();
        this.background = chart.getBackground();
        this.foreground = chart.getForeground();
        this.xlabel = chart.getXlabel();
        this.ylabel = chart.getYlabel();
        this.orientation = chart.getOrientation();
        this.colors = chart.getColors();
        this.chart3d = chart.getIs3d();
        this.legend = chart.getLegend();
        this.legendPosition = chart.getLegendPosition();
        this.legendFontSize = chart.getLegendFontSize();
        this.legendBorder = chart.getLegendBorder();
        this.antialias = chart.getAntialias();
        this.outline = chart.getOutline();
        this.barOutline = chart.getBarOutline();
        this.output = chart.getOutput();
        this.generateMap = chart.getGenerateMap();
        this.domainGridLines = chart.getDomainGridLines();
        this.rangeGridLines = chart.getRangeGridLines();
        this.lineStokeWidth = chart.getLineStrokeWidth();
        this.dataTooltipFormat = chart.getDataTooltipFormat();
        this.pieLabelBackground = chart.getPieLabelBackground();
        this.pieLabelOutline = chart.getPieLabelOutline();

        createExtensions(chart);
    }

    private void createExtensions(UIChart chart) {
        extensions = new ArrayList();
        for (Iterator iterator = chart.getChildren().iterator(); iterator
                .hasNext();) {
            // For now we only have ChartAxis as extension.
            extensions.add(new ChartAxisData((UIChartAxis) iterator.next()));
        }
    }

    public int getAlpha() {
        return alpha;
    }

    public void setAlpha(int alpha) {
        this.alpha = alpha;
    }

    public boolean isAntialias() {
        return antialias;
    }

    public void setAntialias(boolean antialias) {
        this.antialias = antialias;
    }

    public String getBackground() {
        return background;
    }

    public void setBackground(String background) {
        this.background = background;
    }

    public String getForeground() {
        return foreground;
    }

    public void setForeground(String foreground) {
        this.foreground = foreground;
    }

    public boolean isChart3d() {
        return chart3d;
    }

    public void setChart3d(boolean chart3d) {
        this.chart3d = chart3d;
    }

    public String getColors() {
        return colors;
    }

    public void setColors(String colors) {
        this.colors = colors;
    }

    public Object getDatasource() {
        return datasource;
    }

    public void setDatasource(Object datasource) {
        this.datasource = datasource;
    }

    public int getDepth() {
        return depth;
    }

    public void setDepth(int depth) {
        this.depth = depth;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public boolean isLegend() {
        return legend;
    }

    public void setLegend(boolean legend) {
        this.legend = legend;
    }

    public float getLegendFontSize() {
        return legendFontSize;
    }

    public void setLegendFontSize(float legendFontSize) {
        this.legendFontSize = legendFontSize;
    }

    public boolean isLegendBorder() {
        return legendBorder;
    }

    public void setLegendBorder(boolean legendBorder) {
        this.legendBorder = legendBorder;
    }

    public String getLegendPosition() {
        return legendPosition;
    }

    public void setLegendPosition(String legendPosition) {
        this.legendPosition = legendPosition;
    }

    public String getOrientation() {
        return orientation;
    }

    public void setOrientation(String orientation) {
        this.orientation = orientation;
    }

    public boolean isOutline() {
        return outline;
    }

    public void setOutline(boolean outline) {
        this.outline = outline;
    }

    public boolean isBarOutline() {
        return barOutline;
    }

    public void setBarOutline(boolean barOutline) {
        this.barOutline = barOutline;
    }

    public int getStartAngle() {
        return startAngle;
    }

    public void setStartAngle(int startAngle) {
        this.startAngle = startAngle;
    }

    public double getExplode() {
        return explode;
    }

    public void setExplode(double explode) {
        this.explode = explode;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public String getXlabel() {
        return xlabel;
    }

    public void setXlabel(String xlabel) {
        this.xlabel = xlabel;
    }

    public String getYlabel() {
        return ylabel;
    }

    public void setYlabel(String ylabel) {
        this.ylabel = ylabel;
    }

    public String getOutput() {
        return output;
    }

    public void setOutput(String output) {
        this.output = output;
    }

    public List getExtensions() {
        return extensions;
    }

    public void setExtensions(List extensions) {
        this.extensions = extensions;
    }

    public String getGenerateMap() {
        return generateMap;
    }

    public void setGenerateMap(String generateMap) {
        this.generateMap = generateMap;
    }

    public boolean isDomainGridLines() {
        return domainGridLines;
    }

    public void setDomainGridLines(boolean domainGridLines) {
        this.domainGridLines = domainGridLines;
    }

    public boolean isRangeGridLines() {
        return rangeGridLines;
    }

    public void setRangeGridLines(boolean rangeGridLines) {
        this.rangeGridLines = rangeGridLines;
    }

    public float getLineStokeWidth() {
        return lineStokeWidth;
    }

    public void setLineStokeWidth(float lineStokeWidth) {
        this.lineStokeWidth = lineStokeWidth;
    }

    public String getDataTooltipFormat() {
        return dataTooltipFormat;
    }

    public void setDataTooltipFormat(String dataTooltipFormat) {
        this.dataTooltipFormat = dataTooltipFormat;
    }

    public String getPieLabelBackground() {
        return pieLabelBackground;
    }

    public void setPieLabelBackground(String pieLabelBackground) {
        this.pieLabelBackground = pieLabelBackground;
    }

    public String getPieLabelOutline() {
        return pieLabelOutline;
    }

    public void setPieLabelOutline(String pieLabelOutline) {
        this.pieLabelOutline = pieLabelOutline;
    }
}